package com.febers.ihealth.fragment

import com.febers.ihealth.AnalyzeActivity
import com.febers.ihealth.R
import com.febers.ihealth.base.BaseFragment
import com.febers.ihealth.entity.ReleaseNextSurveyEvent
import com.febers.ihealth.entity.SurveyFinishEvent
import com.febers.ihealth.utils.*
import kotlinx.android.synthetic.main.survey_maibo.*

class SurveyMaibo: BaseFragment() {

    private var chooseGroup = false
    private var chooseButton = false

    override fun setView(): Int = R.layout.survey_maibo

    override fun initView() {
        radio_group_maibo_fuchen.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId) {
                R.id.radio_button_maifu -> {
                    user.maifu = true
                    user.maichen = false
                }
                R.id.radio_button_maichen -> {
                    user.maifu = false
                    user.maichen = true
                }
            }
            radio_button_maixiangbumingque.clearCheck()
            chooseGroup = true
        }
        radio_group_maibo_shuchi.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId) {
                R.id.radio_button_maishu -> {
                    user.maishu = true
                    user.maichi = false
                }
                R.id.radio_button_maichi -> {
                    user.maishu = false
                    user.maichi = true
                }
            }
            radio_button_maixiangbumingque.clearCheck()
            chooseGroup = true
        }
        radio_button_maihua.setOnCheckedChangeListener { buttonView, isChecked ->
            user.maihua = isChecked
            if (!user.maixian) {
                chooseButton = isChecked
            }
            if (isChecked) {
                radio_button_maixiangbumingque.clearCheck()
            }
        }
        radio_button_maixian.setOnCheckedChangeListener { buttonView, isChecked ->
            user.maixian = isChecked
            if (!user.maihua) {
                chooseButton = isChecked
            }
            if (isChecked) {
                radio_button_maixiangbumingque.clearCheck()
            }
        }
        radio_button_maixiangbumingque.setOnCheckedChangeListener { buttonView, isChecked ->
            chooseButton = isChecked
            if (isChecked) {
                radio_group_maibo_fuchen.clearCheck()
                radio_group_maibo_shuchi.clearCheck()
                radio_button_maihua.clearCheck()
                radio_button_maixian.clearCheck()
                user.maifu = false
                user.maichen = false
                user.maishu = false
                user.maichi = false
                user.maixian = false
                user.maihua = false
            }
            illnessList.addOrRemove("脉象不明确", isChecked)
        }
        btn_into_analysis.setOnClickListener {
            if (chooseButton || chooseGroup) {
                activity?.nav(AnalyzeActivity::class.java)
                Event.post(SurveyFinishEvent(true))
            } else {
                activity?.toast("请您完成必要信息的选择")
            }
        }
    }

    override fun lazyInit() {
    }
}